using System;
using System.Globalization;
using System.Windows.Data;

namespace WPFTemplateLib.WpfConverters
{
	/// <summary>
	/// [转换器] 对象是否为空（字符串判断 IsNullOrEmpty）
	/// </summary>
	public class IsNullOrEmptyObjectConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if(value is string str)
			{
				if(string.IsNullOrEmpty(str))
				{
					return true;
				}
				return false;
			}
			else
			{
				return value == null;
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new InvalidOperationException($"{nameof(IsNullOrEmptyObjectConverter)} can only be used OneWay.");
		}
	}
}
